#ifndef PROCESS_H
#define PROCESS_H

#include <stdint.h>
#include <stdbool.h>
#include "config.h"
#include "kernel.h"
#include "task.h"
#include <stddef.h>

typedef unsigned char PROCESS_TYPE;
#define PROCESS_FILETYPE_ELF    0
#define PROCESS_FILETYPE_BINARY 1

struct process
{
    // The process id
    uint16_t id;

    char filename[PEACHOS_MAX_PATH];

    // The main process task
    struct task *task;

    // The memory (malloc) allocations of the process
    void *alloctions[PEACHOS_MAX_PROGRAM_ALLOCATIONS];

    PROCESS_TYPE filetype;
    union
    {
        // The physical pointer to the processs memory.
        void *ptr;
        struct elf_file *elf_file;
    };

    // The physical pointer to the stack memory
    void *stack;

    // The size of the data pointed to by "ptr"
    uint32_t size;

    struct keyboard_buffer
    {
        char buffer[PEACHOS_KEYBOARD_BUFFER_SIZE];
        int tail;
        int head;
    } keyboard;
};

int process_switch(struct process *process);
struct process *process_current();
int process_load(const char *filename, struct process **process);
int process_load_switch(const char *filename, struct process **process);
int process_load_for_slot(const char *filename, struct process **process, int process_slot);
void *process_malloc(struct process *process, size_t size);
void process_free(struct process *process, void *ptr);

#endif